<script>
	import {
		getPic
	} from '@/api/points'
	export default {
		data() {
			return {
				picUrl: '',
				sourceUrl: '',
				toUrl: ''
			}
		},
		methods: {
			getPic(params) {
				if (params) {
					getPic({
						bs: params
					}).then(res => {
						this.picUrl = res.data[0].pic
						this.sourceUrl = res.data[0].url
						this.toUrl = res.data[0].tourl
						uni.setStorageSync('route', this.sourceUrl)
						uni.setStorageSync('picUrl', this.picUrl)
						uni.setStorageSync('toUrl',this.toUrl)
						uni.setStorageSync('mt', res.data[0].mt)
						// if (!this.picUrl) {
						// 	this.navigateToIndex()
						// }else{
						// 	uni.navigateTo({
						// 		url:"/pages/advertisement/advertisement"
						// 	})
						// }
					})
				}
			},
			navigateToIndex() {
				return
				if (uni.getStorageSync('toUrl')) {
					window.location.href = uni.getStorageSync('toUrl')
				} else {
					uni.navigateTo({
						url: '/pages/index/index'
					})
				}
			},

			getUrlParam(name) {
				// 获取完整的URL的查询参数部分
				const searchParams = new URLSearchParams(window.location.search)
				const hashParams = new URLSearchParams(window.location.hash.split('?')[1] || '')
		
				// 优先从 search 中获取，没有则从 hash 中获取
				return searchParams.get(name) || hashParams.get(name) || null
			},
		},
		onLaunch: async function() {
			console.log('App Launch')
			let bs = this.getUrlParam('bs')
			await this.getPic(bs)
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
